/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MainWindow.java
 *
 * Created on Sep 18, 2010, 3:30:19 PM
 */
package checker.sdchecker;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import javax.swing.JFileChooser;
import javax.swing.SwingUtilities;

/**
 * 
 * @author takeshi
 */
public class MainWindow extends javax.swing.JFrame implements Observer {

    /** Creates new form MainWindow */
    public MainWindow() {
        initComponents();
        this.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                service.shutdownNow();
            }

        });
    }

    private final ExecutorService service = Executors.newFixedThreadPool(1);

    public static final long ONE_MB = 1024 * 1024;

    private static final long[] SIZES = { WritePartitionTester.ONE_GIG, 100 * ONE_MB, 10 * ONE_MB, ONE_MB };

    private void doStart(File root) throws IOException, NumberFormatException {
        this.startBtn.setText("Cancel");
        this.progressOffset = 0;
        int numThreads = Integer.parseInt(this.jComboBox1.getSelectedItem().toString());
        final WritePartitionTester wTester;
        final ReadPartitionTester rTester;
        long fileSize = SIZES[this.jComboBox2.getSelectedIndex()];
        if (jRadioButton2.isSelected()) {
            long size = Long.parseLong(this.jTextField2.getText());
            wTester = new WritePartitionTester(root, numThreads, size, fileSize);
            rTester = new ReadPartitionTester(root, numThreads, size, wTester.getSelectedFiles());
        } else {
            wTester = new WritePartitionTester(root, numThreads, root.getFreeSpace(), fileSize);
            rTester = new ReadPartitionTester(root, numThreads, wTester.getSelectedFiles());
        }
        wTester.addObserver(new CheckResultObserver(writeFilesTF, writeBytesTF, writeTimeTF, writeSpeedTF, writeRemainingTF));
        wTester.addObserver(this);
        this.service.submit(wTester);
        this.totalProgressBar.setMaximum(wTester.getSelectedFiles().length * 2);
        
        service.submit(new Runnable() {

            @Override
            public void run() {
                progressOffset = wTester.getSelectedFiles().length;
            }});
        
        write = wTester;
        rTester.addObserver(new CheckResultObserver(readFilesTF, readBytesTF, readTimeTF, readSpeedTF, readReaminigTF));
        rTester.addObserver(this);
        service.submit(rTester);
        read = rTester;
        if (this.jCheckBox1.isSelected()) {
            service.submit(new Runnable() {

                @Override
                public void run() {
                    rTester.eraseAllFiles();
                }
            });
        }
        service.submit(new Runnable() {

            @Override
            public void run() {
                write = null;
                read = null;
                SwingUtilities.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        startBtn.setText("Start");
                    }
                });
            }
        });
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed"
    // desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jTextField4 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        selectedFileTF = new javax.swing.JTextField();
        selectPartitionBtn = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        entirePartitionRadio = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        startBtn = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        writeFilesTF = new javax.swing.JTextField();
        writeBytesTF = new javax.swing.JTextField();
        writeTimeTF = new javax.swing.JTextField();
        writeSpeedTF = new javax.swing.JTextField();
        writeRemainingTF = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        jLabel16 = new javax.swing.JLabel();
        readFilesTF = new javax.swing.JTextField();
        readBytesTF = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        jLabel18 = new javax.swing.JLabel();
        readTimeTF = new javax.swing.JTextField();
        readSpeedTF = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        readReaminigTF = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        totalProgressBar = new javax.swing.JProgressBar();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel21 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();

        jTextField4.setText("jTextField4");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Partition:");

        selectPartitionBtn.setText("...");
        selectPartitionBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                selectPartitionBtnActionPerformed(evt);
            }
        });

        jLabel2.setText("Test Size:");

        buttonGroup1.add(entirePartitionRadio);
        entirePartitionRadio.setSelected(true);
        entirePartitionRadio.setText("Entire Partition");

        buttonGroup1.add(jRadioButton2);
        jRadioButton2.setText("Custom:");
        jRadioButton2.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jRadioButton2StateChanged(evt);
            }
        });

        jTextField2.setEnabled(false);

        jLabel3.setText("Number of Threads:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "4", "8", "16" }));

        startBtn.setText("Start");
        startBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startBtnActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Write Progress"));

        jLabel4.setText("Files:");

        jLabel5.setText("Bytes:");

        jLabel6.setText("Elapsed:");

        jLabel7.setText("Speed:");

        jLabel9.setText("Remaining:");

        writeFilesTF.setEditable(false);

        writeBytesTF.setEditable(false);

        writeTimeTF.setEditable(false);

        writeSpeedTF.setEditable(false);

        writeRemainingTF.setEditable(false);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                jPanel1Layout.createSequentialGroup().addContainerGap().addGroup(
                        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel9).addComponent(jLabel7).addComponent(
                                jLabel5).addComponent(jLabel4).addComponent(jLabel6)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(
                                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(writeBytesTF,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE).addComponent(writeFilesTF,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE).addComponent(writeTimeTF,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE).addComponent(writeSpeedTF,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE).addComponent(writeRemainingTF,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, 337, Short.MAX_VALUE)).addContainerGap()));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                jPanel1Layout.createSequentialGroup().addGroup(
                        jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel4).addComponent(writeFilesTF,
                                javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel5).addComponent(writeBytesTF,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel6).addComponent(writeTimeTF,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel7).addComponent(writeSpeedTF,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel9).addComponent(
                                        writeRemainingTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Read Progress"));

        jLabel16.setText("Files:");

        readFilesTF.setEditable(false);

        readBytesTF.setEditable(false);

        jLabel17.setText("Bytes:");

        jLabel18.setText("Elapsed:");

        readTimeTF.setEditable(false);

        readSpeedTF.setEditable(false);

        jLabel19.setText("Speed:");

        jLabel20.setText("Remaining:");

        readReaminigTF.setEditable(false);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                jPanel4Layout.createSequentialGroup().addContainerGap().addGroup(
                        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel20).addComponent(jLabel19)
                                .addComponent(jLabel17).addComponent(jLabel16).addComponent(jLabel18)).addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(readBytesTF,
                                javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE).addComponent(readFilesTF, javax.swing.GroupLayout.DEFAULT_SIZE,
                                346, Short.MAX_VALUE).addComponent(readTimeTF, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE).addComponent(
                                readSpeedTF, javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE).addComponent(readReaminigTF,
                                javax.swing.GroupLayout.DEFAULT_SIZE, 346, Short.MAX_VALUE)).addContainerGap()));
        jPanel4Layout.setVerticalGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                jPanel4Layout.createSequentialGroup().addGroup(
                        jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel16).addComponent(readFilesTF,
                                javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel17).addComponent(readBytesTF,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel18).addComponent(readTimeTF,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel19).addComponent(readSpeedTF,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel20).addComponent(
                                        readReaminigTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));

        jLabel8.setText("Total Progress:");

        totalProgressBar.setMaximum(-1);

        jCheckBox1.setSelected(true);
        jCheckBox1.setText("Erase files after test");

        jLabel21.setText("File Size:");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1 gb", "100 mb", "10 mb", "1 mb" }));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup().addGap(59, 59, 59).addGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel2).addComponent(jLabel1)).addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(entirePartitionRadio).addGroup(
                                layout.createSequentialGroup().addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false).addGroup(
                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                layout.createSequentialGroup().addComponent(jRadioButton2).addPreferredGap(
                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jTextField2)).addComponent(
                                                selectedFileTF, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 261,
                                                Short.MAX_VALUE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addGroup(
                                                layout.createSequentialGroup().addComponent(jCheckBox1).addGap(10, 10, 10).addComponent(startBtn)).addGroup(
                                                layout.createSequentialGroup().addGroup(
                                                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING).addComponent(jLabel21).addGroup(
                                                                layout.createSequentialGroup().addComponent(selectPartitionBtn).addPreferredGap(
                                                                        javax.swing.LayoutStyle.ComponentPlacement.RELATED, 124, Short.MAX_VALUE).addComponent(
                                                                        jLabel3))).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                        .addGroup(
                                                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false).addComponent(
                                                                        jComboBox2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(
                                                                        jComboBox1, 0, 219, Short.MAX_VALUE)))))).addContainerGap()).addGroup(
                layout.createSequentialGroup().addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                        Short.MAX_VALUE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel4,
                        javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGroup(
                layout.createSequentialGroup().addContainerGap().addComponent(jLabel8).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(totalProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 778, Short.MAX_VALUE).addContainerGap()));
        layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                layout.createSequentialGroup().addContainerGap().addGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1).addComponent(selectedFileTF,
                                javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(selectPartitionBtn).addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(jLabel3)).addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel2).addComponent(entirePartitionRadio)
                                        .addComponent(jLabel21)).addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jRadioButton2).addComponent(jTextField2,
                                javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(startBtn).addComponent(jCheckBox1)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jPanel4,
                                        javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jPanel1,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addGroup(
                                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel8).addComponent(totalProgressBar,
                                        javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addContainerGap()));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jRadioButton2StateChanged(javax.swing.event.ChangeEvent evt) {// GEN-FIRST:event_jRadioButton2StateChanged
        jTextField2.setEnabled(jRadioButton2.isSelected());
    }// GEN-LAST:event_jRadioButton2StateChanged

    private void selectPartitionBtnActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_selectPartitionBtnActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.showOpenDialog(this);
        File selected = chooser.getSelectedFile();
        if (selected != null) {
            this.selectedFileTF.setText(selected.getAbsolutePath());
        }
    }// GEN-LAST:event_selectPartitionBtnActionPerformed

    private volatile PartitionTester write, read;

    private void startBtnActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_startBtnActionPerformed
        this.totalProgressBar.setMaximum(0);
        this.progressOffset = 0;
        if (write != null || read != null) {
            // should stop
            write.forceStop();
            read.forceStop();
            write = null;
            read = null;
        } else if (this.selectedFileTF.getText().length() > 0) {
            File root = new File(this.selectedFileTF.getText());
            try {
                if (root.exists()) {
                    doStart(root);
                }
            } catch (IOException iOException) {
                iOException.printStackTrace();
            }
        }
    }// GEN-LAST:event_startBtnActionPerformed

    /**
     * @param args
     *        the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new MainWindow().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JRadioButton entirePartitionRadio;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField readBytesTF;
    private javax.swing.JTextField readFilesTF;
    private javax.swing.JTextField readReaminigTF;
    private javax.swing.JTextField readSpeedTF;
    private javax.swing.JTextField readTimeTF;
    private javax.swing.JButton selectPartitionBtn;
    private javax.swing.JTextField selectedFileTF;
    private javax.swing.JButton startBtn;
    private javax.swing.JProgressBar totalProgressBar;
    private javax.swing.JTextField writeBytesTF;
    private javax.swing.JTextField writeFilesTF;
    private javax.swing.JTextField writeRemainingTF;
    private javax.swing.JTextField writeSpeedTF;
    private javax.swing.JTextField writeTimeTF;
    // End of variables declaration//GEN-END:variables

    private volatile int progressOffset;

    @Override
    public void update(Observable o, Object arg) {
        if (arg instanceof Exception) {
            ((Exception) arg).printStackTrace();
        } else if (arg instanceof TestResult) {
            TestResult tr = (TestResult) arg;
            totalProgressBar.setValue(progressOffset + tr.getCurrentFiles());
        }
    }
}
